// 引入常量
import { SET_CATEGORYLIST_STATE } from "../category-type";

// 引入api中的请求方法
import { reqCategoryList } from "@/api";

const state = {
  // 设置初始化数据状态
  categoryList: [],
};
const mutations = {
  // 设置三级分类列表数据的值
  [SET_CATEGORYLIST_STATE](state, payload) {
    state.categoryList = payload.categoryList;
  },
};

const actions = {
  // 异步请求数据  commit 来自$store
  async getCategoryList({ commit }) {
    try {
      const re = await reqCategoryList();
      console.log("re",re);
      commit(SET_CATEGORYLIST_STATE, { categoryList: re });
      // console.log(categoryList, "categoryList");
    } catch (e) {
      console.log(e.message, "message");
    }
  },
};
const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
